phantom-types | Phantom types for Python | Code Analyzer library
kandi X-RAY | phantom-types Summary
kandi X-RAY | phantom-types Summary
Phantom types for Python.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Resolve the bound object
- Check if b is a subclass of b
- Checks if the given type is not known
- Interpret the explicit bound type
- Return a parser for the given bound
- Bind the wrapped function to the wrapped function
- Return the string representation of an object
- Creates a function that evaluates each of the given predicates
- Creates a predicate for inclusive exclusive inclusive
- Get copyright from LICENSE file
- Parse a phone number
- Creates a function that returns a comparison of the given value
- Creates a predicate that can be used to create an identical object
- Creates a predicate that evaluates to exclusive
- Creates a predicate that evaluates to an inclusive value
- Creates a predicate for inclusive range
- Creates a predicate function that returns a predicate that evaluates to True
- Creates a predicate for xor
- Creates a predicate that evaluates the value of the given predicate
- Creates a predicate that returns a predicate that evaluates to the given value
- Creates a predicate function that returns a predicate that matches the given pattern
- Creates a comparison function that evaluates to a given predicate
- Parse an instance
- Creates a function that evaluates to true if the given predicates
- Creates a function that evaluates to one of the given predicates
- Decorator to catch exceptions
phantom-types Key Features
phantom-types Examples and Code Snippets
class Name(str, Phantom, predicate=contained({"Jane", "Joe"})):
@classmethod
def __schema__(cls) -> Schema:
return super().__schema__() | {
"description": "Either Jane or Joe",
"format": "custom-name",
from phantom import Phantom
from phantom.predicates.collection import contained
class Name(str, Phantom, predicate=contained({"Jane", "Joe"})):
...
def greet(name: Name):
print(f"Hello {name}!")
greet(Name.parse("Jane"))
joe = "Joe"
ass
$ python3 -m pip install .[test,pydantic,phonenumbers]
$ pytest
# or
$ make test
# configure hooks to run when pushing
$ pre-commit install -t pre-push
# or when committing
$ pre-commit install -t pre-commit
# run all checks
$ pre-commit run --all-
Community Discussions
Trending Discussions on phantom-types
QUESTION
Compiling a program that contains a type evidence parameter in Scala (such as T <:< U
) can cause a warning when -Ywarn-unused
is passed to the compiler. Especially in the case when the type evidence parameter is used to verify a constraint encoded using phantom types, this warning is likely to occur.
As an example, compiling the file here: https://github.com/hseeberger/demo-phantom-types/blob/master/src/main/scala/de/heikoseeberger/demophantomtypes/Hacker.scala returns the following:
# scalac -Ywarn-unused Hacker.scala
Hacker.scala:42: warning: parameter value ev in method hackOn is never used
def hackOn(implicit ev: IsCaffeinated[S]): Hacker[State.Decaffeinated] = {
^
Hacker.scala:47: warning: parameter value ev in method drinkCoffee is never used
def drinkCoffee(implicit ev: IsDecaffeinated[S]): Hacker[State.Caffeinated] = {
^
two warnings found
It's clear to me that the parameter ev
is not actually necessary at runtime, but the parameter is useful at compile time. Is there any way to instruct the compiler to ignore this case, while still raising the warning for unused function parameters in other contexts?
For example, I think instructing the compiler to ignore implicit parameters of class <:<
or =:=
would solve this issue, but I'm not sure how that could be accomplished.
ANSWER
Answered 2017-Sep-09 at 17:12I often find myself adding this because of either -Ywarn-unused
or -Ywarn-value-discard
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install phantom-types
You can use phantom-types like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page