Skip to content

Refs #5383: Document that aliasing dataclass fails - #5387

Merged
ilevkivskyi merged 3 commits into
python:masterfrom
wkschwartz:doc-no-dataclass-alias
Aug 2, 2018
Merged

ilevkivskyi merged 3 commits into
python:masterfrom
wkschwartz:doc-no-dataclass-alias

Conversation

@wkschwartz

Copy link
Copy Markdown
Contributor

This documentation is a temporary solution. It should be altered or
removed when #5383 is fixed.

I inserted the whole example from #5383. If you think that's too much, feel free to modify. I've granted edit permissions to maintainers.

This documentation is a temporary solution. It should be altered or
removed when python#5383 is fixed

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this.

Can you add a comment for each "badly decorated class" explaining what's wrong with its decoration? And please come up with better names than 1, 2, 3. What's fine to put in a bug report doesn't necessarily look right in the docs!

Comment thread docs/source/additional_features.rst Outdated
return dataclass(cls)

@dataclass_alias
class BadlyDecoratedClass1: arg1: int

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize this syntax was legal. I think it's better to put the field on a separate line.

@gvanrossum

Copy link
Copy Markdown
Member

@wkschwartz Please respond to the review feedback. (Please use a new local commit, or several, to update your changes -- don't use git commit --amend; git push -f.)


Mypy does not yet recognize aliases of ``dataclasses.dataclass``, and will
probably never recognize dynamically computed decorators. The following examples
do **not** work:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually skip the examples, the textual formulation is already clear (except maybe the dynamically computed decorators).

- Rename example classes
- Cut down on number of examples
- Add comment to each example to explain what's wrong
- Use more traditional code style
@wkschwartz

Copy link
Copy Markdown
Contributor Author

@ilevkivskyi I removed one of the three examples in response to #5387 (comment) in dc742c8

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks almost ready now. Could you please fix one last comment and I will merge it.

Comment thread docs/source/additional_features.rst Outdated
Mypy doesn't recognize this as a dataclass because it is decorated by an
alias of `dataclass` rather than by `dataclass` itself.
"""
arg1: int

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use attr (or similar) instead of arg1?

@ilevkivskyi
ilevkivskyi merged commit 737470e into python:master Aug 2, 2018
@wkschwartz
wkschwartz deleted the doc-no-dataclass-alias branch August 2, 2018 16:09
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.

4 participants