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

Problem with path.open #68

Closed
rpspringuel opened this issue Dec 14, 2024 · 4 comments
Closed

Problem with path.open #68

rpspringuel opened this issue Dec 14, 2024 · 4 comments

Comments

@rpspringuel
Copy link

I'm working with the syllabify script from hyphen-la repository and am running up against what appears to be a problem with Pyphen. The last lines of the stack trace read as follows:

File "/Users/ss/Library/Python/3.12/lib/python/site-packages/pyphen/__init__.py", line 117, in __init__
    with path.open('rb') as fd:
         ^^^^^^^^^
AttributeError: 'str' object has no attribute 'open'

This suggests to me that the path variable is being misinterpreted as a str rather than as a path to a file that can be opened. Doing some search online, I found a StackOverflow question which talks about this sort of error, but it's flagged for Python 2.7, not Python 3.*. Still, I took it as a starting point and came up with this diff.patch.

I'm not submitting this as a PR because it removes the attempted detection of encoding and instead relies on the input being in Unicode (the default assumption for Python). I couldn't find an encoding detection method that doesn't require importing a new package and I didn't want to add a dependency.

@liZe
Copy link
Member

liZe commented Dec 14, 2024

Hi!

Thanks for the report. Could you please share the whole stack?

@rpspringuel
Copy link
Author

The whole stack trace was as follows:

syllabify returned error number 1
Traceback (most recent call last):
  File "/Users/ss/Documents/Programming/hyphen-la/syllabifier/syllabify.py", line 157, in <module>
    hyphenator = pyphen.Pyphen(filename=dir_path+'/../patterns/hyph_la_'+args.mode+'.dic',left=lefthyphenmin,right=righthyphenmin)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ss/Library/Python/3.12/lib/python/site-packages/pyphen/__init__.py", line 223, in __init__
    hdcache[filename] = HyphDict(filename)
                        ^^^^^^^^^^^^^^^^^^
  File "/Users/ss/Library/Python/3.12/lib/python/site-packages/pyphen/__init__.py", line 117, in __init__
    with path.open('rb') as fd:
         ^^^^^^^^^
AttributeError: 'str' object has no attribute 'open'

@liZe liZe closed this as completed in c00863f Dec 15, 2024
@liZe
Copy link
Member

liZe commented Dec 15, 2024

Should be fixed in main, feedback is welcome!

@rpspringuel
Copy link
Author

Initial testing has it working just fine. Thanks.

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

No branches or pull requests

2 participants