Skip to content

[rfc] Make sentinel objects instances of themselves - #18

Merged
njsmith merged 1 commit into
masterfrom
unique-type-sentinels
Nov 2, 2016
Merged

njsmith merged 1 commit into
masterfrom
unique-type-sentinels

Conversation

@njsmith

@njsmith njsmith commented Oct 25, 2016 •

Copy link
Copy Markdown
Member

This is a slightly wacky solution to #8. By "slightly wacky" I mean that contains the following line of code:

cls.__class__ = cls

Based on watching some of his talks I feel fairly confident that @dabeaz will appreciate this, but I am less certain about whether it's actually a good idea, so would appreciate comments ;-).

Actually, my main hesitation is that I'm not really sure whether doing table-based dispatch on the return value from next_event ever makes much sense -- in my experience so far, libraries usually have a pretty small and specific set of events that they're looking for at any given time. But maybe it's useful for those who like more declarative state-machine kind of approaches? And it's not a big deal to support; it's like 2 extra lines of code that don't touch anything else in h11 at all.

This is a reworked version of @RazerM's work in #11.

This is a reworked version of @RazerM's work in gh-11.
@codecov-io

codecov-io commented Oct 25, 2016 •

Copy link
Copy Markdown

Current coverage is 100% (diff: 100%)

Merging #18 into master will not change coverage

@@           master   #18   diff @@
===================================
  Files          20    20          
  Lines         867   869     +2   
  Methods         0     0          
  Messages        0     0          
  Branches      169   169          
===================================
+ Hits          867   869     +2   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update 9c0a553...f6c685d

@njsmith

njsmith commented Nov 1, 2016

Copy link
Copy Markdown
Member Author

@Lukasa: do you happen do have any opinion on this?

@Lukasa

Lukasa commented Nov 1, 2016

Copy link
Copy Markdown
Member

The implementation is bonkers, but the goal is sound. Wanting to do dict-dispatch or the equivalent of singledispatch based on event type is a good idea, and if this can do that without difficulty or reduction in supported Python versions then I say why not?

@njsmith

njsmith commented Nov 2, 2016

Copy link
Copy Markdown
Member Author

It's not entirely unprecedented: after all, type.__class__ is type :-). But, yeah, bonkers is a good description :-)

Oh well, let's do it!

@njsmith
njsmith merged commit 3daedec into master Nov 2, 2016
@njsmith
njsmith deleted the unique-type-sentinels branch November 2, 2016 05:46
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.

3 participants