hundreds-father-404
05/17/2022, 6:32 PMNone | ExportPythonTool
for a rule return type?
@dataclass(frozen=True)
class ExportPythonTool:
resolve_name: str
pex_request: PexRequest
hundreds-father-404
05/17/2022, 6:34 PM@rule
async def black_export(
_: BlackExportSentinel, black: Black, python_setup: PythonSetup
) -> ExportPythonTool:
constraints = await _black_interpreter_constraints(black, python_setup)
return ExportPythonTool(
resolve_name=black.options_scope,
pex_request=black.to_pex_request(interpreter_constraints=constraints),
)
I'm trying to add if not black.export: return ExportPythonTool(None)
or something equivalentwide-midnight-78598
05/17/2022, 6:34 PMbitter-ability-32190
05/17/2022, 6:35 PMwide-midnight-78598
05/17/2022, 6:35 PMwide-midnight-78598
05/17/2022, 6:36 PMhundreds-father-404
05/17/2022, 6:36 PMMaybeExportPythonTool
, but now we have two class definitions and imports - ewbitter-ability-32190
05/17/2022, 6:37 PMhundreds-father-404
05/17/2022, 6:37 PMFeels like a NullObject patternTHat's how we normally solve this, e.g.
FmtResult.skip()
bitter-ability-32190
05/17/2022, 6:37 PMhundreds-father-404
05/17/2022, 6:37 PMresolve_name: str
, and make it be pex_request: PexRequest | None
! It's cheap to compute the resolve name
Before I was thinking of making both fields | None
, which is ickyhundreds-father-404
05/17/2022, 6:39 PMcurved-television-6568
05/17/2022, 6:43 PMskip
field to ExportPythonTool.skip
?hundreds-father-404
05/17/2022, 6:44 PMPexRequest()
too - there is no Nully version of itcurved-television-6568
05/17/2022, 6:45 PMasync def black_export(
_: BlackExportSentinel, black: Black, python_setup: PythonSetup
) -> ExportPythonTool:
constraints = await _black_interpreter_constraints(black, python_setup)
return ExportPythonTool(
resolve_name=black.options_scope,
pex_request=black.to_pex_request(interpreter_constraints=constraints),
skip=not black.export,
)
hundreds-father-404
05/17/2022, 6:47 PMawait _black_interpreter_constraints
has a performance hitcurved-television-6568
05/17/2022, 6:47 PMhundreds-father-404
05/17/2022, 6:47 PM@rule
async def black_export(
_: BlackExportSentinel, black: Black, python_setup: PythonSetup
) -> ExportPythonTool:
if not black.export:
return ExportPythonTool(resolve_name=black.options_scope, pex_request=None)
constraints = await _black_interpreter_constraints(black, python_setup)
return ExportPythonTool(
resolve_name=black.options_scope,
pex_request=black.to_pex_request(interpreter_constraints=constraints),
)
curved-television-6568
05/17/2022, 6:47 PMto_pex_request
doesn’t seem expensive (from what I can read)curved-television-6568
05/17/2022, 6:48 PMhundreds-father-404
05/17/2022, 6:59 PM