Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WriteString[] does not handle String filenames. #1195

Open
rocky opened this issue Nov 28, 2024 · 0 comments · May be fixed by #1188
Open

WriteString[] does not handle String filenames. #1195

rocky opened this issue Nov 28, 2024 · 0 comments · May be fixed by #1188

Comments

@rocky
Copy link
Member

rocky commented Nov 28, 2024

Description

WriteString[] does not find a previously-created Stream by filename.

More generally, finding streams by name in Mathics3 is flaky to put it generously.

How to Reproduce

mathics -e 'OpenWrite["/tmp/foo"]; WriteString["/tmp/foo", "bar\n"]'

Output Given

Traceback (most recent call last):
  File "/tmp/bin/mathics", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/main.py", line 532, in main
    result, evaluation = run_it()
                         ^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/main.py", line 524, in run_it
    return evaluation.parse_evaluate(expr, timeout=settings.TIMEOUT), evaluation
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/evaluation.py", line 142, in parse_evaluate
    return self.evaluate(expr, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/evaluation.py", line 241, in evaluate
    result = evaluate()
             ^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/evaluation.py", line 214, in evaluate
    self.last_eval = query.evaluate(self)
                     ^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/eval/tracing.py", line 62, in wrapper
    result = func(expr, evaluation)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/expression.py", line 573, in evaluate
    expr, reevaluate = expr.rewrite_apply_eval_step(evaluation)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/expression.py", line 1408, in rewrite_apply_eval_step
    result = rule.apply(new, evaluation, fully=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 165, in apply
    self.pattern.match(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 464, in match
    basic_match_expression(self, expression, parms)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 889, in basic_match_expression
    self.head.match(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 350, in match_symbol
    pattern_context["yield_func"](pattern_context["vars_dict"], None)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 874, in yield_head
    self.get_pre_choices(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1061, in get_pre_choices_with_order
    pattern_context["yield_choice"](pattern_context["vars_dict"])
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 850, in yield_choice
    self.match_element(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 620, in match_element
    expression_pattern_match_element_process_items(items, items_rest, parms)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1043, in expression_pattern_match_element_process_items
    pattern.get_wrappings(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 525, in get_wrappings
    yield_func(sequence)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1023, in yield_wrapping
    parms["element"].match(
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns/composite.py", line 421, in match
    self.pattern.match(
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns/basic.py", line 141, in match
    yield_func(vars_dict, None)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1020, in match_yield
    yield_func(new_vars, items_rest)
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 137, in yield_match
    new_expression = apply_fn(expression, vars, options, evaluation)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 354, in apply_function
    return self.function(evaluation=evaluation, **vars_noctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/builtin/procedural.py", line 217, in eval
    result = expr.evaluate(evaluation)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/eval/tracing.py", line 62, in wrapper
    result = func(expr, evaluation)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/expression.py", line 573, in evaluate
    expr, reevaluate = expr.rewrite_apply_eval_step(evaluation)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/expression.py", line 1408, in rewrite_apply_eval_step
    result = rule.apply(new, evaluation, fully=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 165, in apply
    self.pattern.match(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 464, in match
    basic_match_expression(self, expression, parms)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 889, in basic_match_expression
    self.head.match(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 350, in match_symbol
    pattern_context["yield_func"](pattern_context["vars_dict"], None)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 874, in yield_head
    self.get_pre_choices(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1061, in get_pre_choices_with_order
    pattern_context["yield_choice"](pattern_context["vars_dict"])
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 850, in yield_choice
    self.match_element(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 620, in match_element
    expression_pattern_match_element_process_items(items, items_rest, parms)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1043, in expression_pattern_match_element_process_items
    pattern.get_wrappings(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 510, in get_wrappings
    yield_func(items[0])
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1023, in yield_wrapping
    parms["element"].match(
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns/composite.py", line 421, in match
    self.pattern.match(
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns/basic.py", line 101, in match
    yield_func(vars_dict, None)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1015, in match_yield
    pattern.match_element(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 620, in match_element
    expression_pattern_match_element_process_items(items, items_rest, parms)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1043, in expression_pattern_match_element_process_items
    pattern.get_wrappings(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 510, in get_wrappings
    yield_func(items[0])
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1023, in yield_wrapping
    parms["element"].match(
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns/composite.py", line 421, in match
    self.pattern.match(
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns/basic.py", line 141, in match
    yield_func(vars_dict, None)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1020, in match_yield
    yield_func(new_vars, items_rest)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 998, in element_yield
    yield_func(
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 137, in yield_match
    new_expression = apply_fn(expression, vars, options, evaluation)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 354, in apply_function
    return self.function(evaluation=evaluation, **vars_noctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/builtin/files_io/files.py", line 1636, in eval
    if stream is None or stream.io is None or stream.io.closed:
       ^^^^^^
UnboundLocalError: cannot access local variable 'stream' where it is not associated with a value

Expected behavior

Data written to file.

Additional context

But seen trying to run Mathics3 package analytica.

@rocky rocky linked a pull request Nov 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant