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

fix MultiStrategyDispatch to work with new GenConverter and attrs inheritance #117

Merged

Conversation

petergaultney
Copy link
Contributor

Because the GenConverter specifically handles generating code for
attrs classes, and because it registers hooks that don't require
function dispatch, singledispatch was preventing subclasses from
having code generated for them, because they would trigger the
previously-generated base class's structure/unstructure code.

This changes MultiStrategyDispatch to allow for a class-based hook to
specifically avoid single-dispatch. Since we know that a given attrs
class can always have code generated for it, we don't really want to
share dispatch across subclasses - like the original Converter, we
want to make sure we're structuring each individual attrs class as its
own separate type.

fixes #116

…eritance

Because the GenConverter specifically handles generating code for
attrs classes, and because it registers hooks that don't require
function dispatch, singledispatch was preventing subclasses from
having code generated for them, because they would trigger the
previously-generated base class's structure/unstructure code.

This changes MultiStrategyDispatch to allow for a class-based hook to
specifically avoid single-dispatch. Since we know that a given attrs
class can always have code generated for it, we don't really want to
share dispatch across subclasses - like the original Converter, we
want to make sure we're structuring each individual attrs class as its
own separate type.
@petergaultney petergaultney force-pushed the bugfix/genconverter-inheritance branch from a25ca9a to 285b608 Compare January 24, 2021 04:10
@codecov
Copy link

codecov bot commented Jan 24, 2021

Codecov Report

Merging #117 (a8f28df) into master (61c9445) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #117      +/-   ##
==========================================
+ Coverage   98.23%   98.25%   +0.02%     
==========================================
  Files           7        7              
  Lines         453      459       +6     
==========================================
+ Hits          445      451       +6     
  Misses          8        8              
Impacted Files Coverage Δ
src/cattr/converters.py 99.01% <100.00%> (ø)
src/cattr/multistrategy_dispatch.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 61c9445...a8f28df. Read the comment docs.

Copy link
Member

@Tinche Tinche left a comment

Choose a reason for hiding this comment

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

Please add a HISTORY entry with a link to the PR and issue and I'll merge this in :)

src/cattr/multistrategy_dispatch.py Outdated Show resolved Hide resolved
@petergaultney
Copy link
Contributor Author

i put the entry in 1.2.0 but if you decide to do a bugfix release first, let me know and I can change it to a 1.1.3.

@petergaultney petergaultney requested a review from Tinche January 25, 2021 02:52
@petergaultney petergaultney force-pushed the bugfix/genconverter-inheritance branch from 02d4793 to a8f28df Compare January 25, 2021 02:56
Copy link
Member

@Tinche Tinche left a comment

Choose a reason for hiding this comment

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

Thanks for this. I might add a few tests and then release this as 1.2.0 in a few days.

@Tinche Tinche merged commit e54fa17 into python-attrs:master Jan 25, 2021
@Tinche
Copy link
Member

Tinche commented Jan 28, 2021

I had to tweak this a little so that direct dispatch is consulted after the singledispatch, not before, to get some tests to pass.

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.

GenConverter doesn't support inheritance
2 participants