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

Parse each format-string component separately #3390

Merged
merged 5 commits into from May 30, 2017

Conversation

Projects
None yet
3 participants
@lincolnq
Contributor

lincolnq commented May 21, 2017

Fixes #3385.

The old code evaluated each FormattedValue as an expression potentially returning the type of the value, rather than a string. But that's wrong, because a FormattedValue can exist on its own when it's not being joined to any other format strings + those FormattedValues need type str. The new code evaluates each FormattedValue by synthesizing '{}'.format(expr) and then, if necessary, joins them in JoinedStr using ''.join(items).

I had to create a new unittest fixture for this with list, str, and int.

@gvanrossum

Just nits, this is basically right.

Show outdated Hide outdated mypy/fastparse.py
Show outdated Hide outdated test-data/unit/fixtures/f_string.pyi

lincolnq added some commits May 21, 2017

Parse each format-string component separately
Fixes #3385.

The old code evaluated each FormattedValue as an expression potentially
returning the type of the value, rather than a string. But that's wrong,
because a FormattedValue can exist on its own when it's not being joined
to any other format strings. The new code evaluates each FormattedValue
by synthesizing '{}'.format(expr) and then, if necessary, joins them in
JoinedStr using ''.join(items).
@lincolnq

This comment has been minimized.

Show comment
Hide comment
@lincolnq

lincolnq May 30, 2017

Contributor

Ready for re-review.

Contributor

lincolnq commented May 30, 2017

Ready for re-review.

@gvanrossum gvanrossum merged commit d4864a9 into python:master May 30, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@gvanrossum

This comment has been minimized.

Show comment
Hide comment
@gvanrossum

gvanrossum May 30, 2017

Member

Thanks!

Member

gvanrossum commented May 30, 2017

Thanks!

carljm added a commit to carljm/mypy that referenced this pull request May 30, 2017

Merge branch 'master' into module-alias
* master: (23 commits)
  Make return type of open() more precise (#3477)
  Add test cases that delete a file during incremental checking (#3461)
  Parse each format-string component separately (#3390)
  Don't warn about returning Any if it is a proper subtype of the return type (#3473)
  Add __setattr__ support (#3451)
  Remove bundled lib-typing (#3337)
  Move version of extensions to post-release (#3348)
  Fix None slice bounds with strict-optional (#3445)
  Allow NewType subclassing NewType. (#3465)
  Add console scripts (#3074)
  Fix 'variance' label.
  Change label for variance section to just 'variance' (#3429)
  Better error message for invalid package names passed to mypy (#3447)
  Fix last character cut in html-report if file does not end with newline (#3466)
  Print pytest output as it happens (#3463)
  Add mypy roadmap (#3460)
  Add flag to avoid interpreting arguments with a default of None as Optional (#3248)
  Add type checking plugin support for functions (#3299)
  Mismatch of inferred type and return type note (#3428)
  Sync typeshed (#3449)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment