In a misdemeanor case the plea of the defendant may be made by the defendant or by the defendant's counsel. If such defendant pleads guilty, the court may, before entering such plea or pronouncing judgment, examine witnesses to ascertain the gravity of the offense committed; and if it appears to the court that a higher offense has been committed than the offense charged in the complaint, the court may order the defendant to be committed or admitted to bail, to answer any indictment which may be found against the defendant by the grand jury, or any complaint which may be filed charging the defendant with such higher offense.
Ca. Pen. Code § 1429