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

add import expression support #12

Merged
merged 3 commits into from
Nov 25, 2018
Merged

add import expression support #12

merged 3 commits into from
Nov 25, 2018

Conversation

ioistired
Copy link
Contributor

If I can figure out how to make a damn link in rST I will document this too.

import_expression was recently relicensed to MIT, and we need MIT instead of
dumb hipster meme licenses
@ioistired
Copy link
Contributor Author

ioistired commented Nov 25, 2018

For more information on Import Expression Parser please see https://github.com/bmintz/import-expression-parser.

Take note of these known issues:

  1. The rejection of multiple ! in one dotted attribute access is inconsistent at this time:
  • a.b.c!.d! is not rejected
  • a.b!.c!.d! is rejected
  • a!.b!.c!.d is rejected
  • a!.b!.c.d is not rejected

These cases act as though only the last ! is present, e.g. a!.b!.c.d is a.b!.c.d.
2. Some other invalid syntax, such as import x! and def foo(*, x!) is not rejected yet.
3. Import expressions within f-strings, such as f'Message creation: {discord.utils!.snowflake_time(ctx.message.created_at)}' are not supported at all. This is due to f-strings being hell to parse, and ! already being supported inside certain f-string format specifiers.

Issues (1) and (2) can be disregarded if you anticipate the user not doing these things, and indeed import collections! will still fail, but with an unexpected error: ModuleNotFoundError: No module named 'collections__IMPORT_EXPR_END'.

Sadly def foo(*, x!) will currently not fail until the user tries to use the function:

>>> import_expression.exec('def foo(*, x!): pass')
>>> inspect.signature(foo)
<Signature (*, x__IMPORT_EXPR_END)>
>>> foo(x=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() got an unexpected keyword argument 'x'

I consider this to be a less acceptable failure since it works until later on. If this is a deal breaker for you, please consider leaving the PR open until I fix this issue, as the issue would be fixed on pypi and not in this PR.

@ioistired ioistired changed the title Import expression add import expression support Nov 25, 2018
@Gorialis Gorialis merged commit c00f1f7 into Gorialis:master Nov 25, 2018
@ioistired ioistired deleted the import_expression branch November 25, 2018 19:41
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 this pull request may close these issues.

2 participants