omry / omegaconf

Flexible Python configuration system. The last one you will ever need.
BSD 3-Clause "New" or "Revised" License
1.88k stars 98 forks source link

fix: `SCMode.INSTANTIATE` for attrs fields with aliases/leading "_" #1135

Closed bzczb closed 6 months ago

bzczb commented 8 months ago

Motivation

attrs classes automatically alias any fields with a leading underscore to a stripped version in that class's __init__(). So, the class

@attr.s
class Foo():
    _bar: int = attr.ib(default=0)

has an __init__() that looks like:

def __init__(self, bar):
    self._bar = bar

This PR changes the structured config instantiation behavior to take aliases into account, when setting up the params for an __init__().

Test Plan

Test test_leading_underscore_fields() added.

Fixes

Fixes #1063

Jasha10 commented 8 months ago

Hi @bzczb, Thanks for submitting these PR's! I will review them shortly.