[Feature Request] Parametrize ```__is__``` dunder
Nobody has claimed this yet.
- Dominant language
- Mojo
- Stars
- 29.8k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Review Mojo's priorities
- I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
Hello,
that feature improved __getitem__ by letting take indexes as parameters (Variant[Int,Bool](1)[Int]),
__is__ might get an improvement by it too, here are some examples:
Example for variant:
struct Variant[*Ts:CollectionElement]():
fn __is__[
other: CollectionElement
](self)->Bool:
return self.isa[other]()
fn main():
var x = Variant[Int,Bool](1)
if x is Int: print(x[Int])
if x is Bool: print(x[Bool])
And for PythonObject:
x = PythonObject(1)
if x is Int: print(int(x))
#if x is List
#if x is Tuple
What is your motivation for this change?
Variant is a nice type that can seem weird for python users, this could make it more user-friendly.
it could also ameliorate any user-created structs in a super user-friendly manner.
Any other details?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked Mojo roadmap and the existing is and getitem entry points, then determine how parameterized type checks should work for Variant and PythonObject. Done means the behavior illustrated in the issue's examples is supported and validated by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100